package com.wms.service.impl;

import com.wms.domain.Emp;
import com.wms.domain.PageBean;
import com.wms.mapper.EmpMapper;
import com.wms.service.EmpService;
import com.wms.utils.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    public PageBean page(Integer page, Integer pageSize, String name, Short gender, LocalDateTime begin, LocalDateTime end) {
        //1.获取总记录数
        Long count = empMapper.count();
        //2.获取分页查询表
        int start = (page - 1) * pageSize;
        List<Emp> empList = empMapper.findByPage(start, pageSize,name,gender,begin,end);
        //3.封装的PageBean对象
        return new PageBean(count, empList);
    }

    @Log
    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }

    @Log
    @Override
    public void insert(Emp emp) {
        emp.setCreateTime(LocalDateTime.now());
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.insert(emp);
    }

    @Override
    public Emp findById(Integer id) {
        return empMapper.findById(id);

    }

    @Log
    @Override
    public void update(Emp emp) {
        emp.setUpdateTime(LocalDateTime.now());
        empMapper.update(emp);
    }

    @Override
    public Emp login(Emp emp) {
        return empMapper.getBynameandPassword(emp);
    }
}
